package Data::Semantic;

use strict;
use warnings;


our $VERSION = '0.03';


use base qw(Class::Accessor::Complex);


__PACKAGE__->mk_new;


sub is_valid {
    my ($self, $value) = @_;
    # value can be undef
    return 1 unless defined $value;

    my $normalized = $self->normalize($value);
    return 0 unless defined $normalized;
    $self->is_valid_normalized_value($normalized);
}


sub normalize {
    my ($self, $value) = @_;
    $value;
}


sub is_valid_normalized_value {
    my ($self, $normalized) = @_;
    defined $normalized;
}


1;


__END__

{% USE p = PodGenerated %}

=head1 NAME

{% p.package %} - Common API for data with semantics attached to them

=head1 SYNOPSIS

    {% p.package %}->new;

=head1 DESCRIPTION

There are various distributions on CPAN dealing with data that has semantics
attached them. For example, an IP address is not just a string, but it has a
format the can be checked.

There is L<Data::Domain>. It does not store the values to be tested, it just
tests them and records messages.

Then there is L<Class::Value>. It does store the value and it records
exceptions.

Both share the same underlying concept of a value that can be tested for
validity. Data::Semantic provides this underlying mechanism. It does not store
the value and it does not record the message. All it does is validate data and
say whether it is good or bad. What L<Data::Domain> or L<Class::Value> do with
this information is their thing.

If you have a new type of semantic data, here is how you can handle it.

    if it can be a Regexp::Common pattern:
        make a Regexp::Common pattern
        make a subclass of Data::Semantic::RegexpAdapter
    else:
        make a subclass of Data::Semantic::Base
        if there is a CPAN module for that data type:
            wrap that module in your semantic data class
            forward methods onto the object if possible

    make an adapter class for Class::Value
    make an adapter class for Data::Domain

=head1 METHODS

=over 4

{% p.write_methods %}

=back

{% p.write_inheritance %}

{% PROCESS standard_pod %}

=cut

